package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import bean.library;
import sql.sqlConnect;
/*
 * 借书的业务逻辑
 */
public class libraryDao {
	//输入借书信息
	public void insertLibrary(library library) throws Exception{
		Connection con = null;
		String sqlStr = "insert into student" +
				" values ('" + library.getBookID()+ "','" + library.getBookName() + "','" +
				 library.getborrowTime()+ "','" + library.getReturnTime() + "','" + library.getPicture()+ "');";
		System.out.println(sqlStr);
		try {
			con = sqlConnect.getConnection();
			PreparedStatement pre = con.prepareStatement(sqlStr);
			pre.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	//获得借书信息
		public List<library> selectAllLibrary () throws Exception{
			Connection con = null;
			PreparedStatement ps = null;
			ResultSet rs = null;
			List<library> libraryList = new ArrayList<library>();
			try{
				con = sqlConnect.getConnection();
				String SqlStr = "select * from library where 1=1";
				ps = con.prepareStatement(SqlStr);
				rs = ps.executeQuery();
				while(rs.next()){
					library library = new library();
					library.setBookID(rs.getString(1));
					library.setBookName(rs.getString(2));
					library.setBorrowTime(rs.getString(3));
					library.setReturnTime(rs.getString(4));
					library.setPicture(rs.getString(5));
					libraryList.add(library);
				}
				return  libraryList;
			}catch (SQLException e){
				System.out.println("查无结果");
				e.printStackTrace();
				return null;
			}
		}
}
